class Solution:
    def reverseBits(self, n: int) -> int:
        MAX = 2**32 - 1
        for i in range(16):
            highTemp = 1 << (32 - (i + 1))
            res = highTemp & n
            high = 0 if res == 0 else 1
            lowTemp = 1 << i
            res = lowTemp & n
            low = 0 if res == 0 else 1
            if high == 1 and low == 0:
                n += lowTemp
                n &= (MAX ^ highTemp)
            elif high == 0 and low == 1:
                n &= (MAX ^ lowTemp)
                n += highTemp

        return n
